package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@ServletComponentScan(basePackages = "com.example.filter")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/delete")
    public int deletedemo(User user){
        return userService.deletedemo(user);
    }
    @RequestMapping("/add")
    public int adddemo(User user){
        return userService.adddemo(user);
    }
    @RequestMapping("/update")
    public int updatedemo(User user){
        return userService.updatedemo(user);
    }
    @RequestMapping("/query")
    public List querydemo(User user){
        return userService.querydemo(user);
    }
    @RequestMapping("/failed")
    public Map<String, String> requestFailed(){

        Map<String, String> map = new HashMap<>();
        map.put("code", "-1");
        map.put("msg", "请求错误");
        return map;
    }
    @RequestMapping("/success/info")
    public User userInfo(){

        User user = new User();
        user.setName("Yansir");
        return user;
    }
//    @RequestMapping("/demo")
//    public List demo(User user){
//        return userService.demo(user);
//    }
//
//    @RequestMapping("/demol")
//    public List demol(@RequestParam Map user){
//        return null;
//    }
}
